/*
 * Created on Tue Oct 03 2017
 * @flow
 * Copyright (c) 2017 jianglinjie
 */
'use strict';
import { User } from '../../src/db/models';
import { registerWithUserName, registerWithPhone } from './ServiceHelper';
import Random from 'random-js';

test('USERNAME_PWD_REGISTER', async () => {  
  let userName = 'T' + (new Random()).string(10);
  let password = '123456';
  let result = await registerWithUserName(userName, password);

  let userDoc = await User.findOne({ userName: userName });
  expect(userDoc).toBeTruthy();
  expect(result.uid).toMatch(userDoc.id);
  expect(result.userName).toMatch(userDoc.userName);
});

test('PHONE_PWD_CAPTCHA_REGISTER', async () => {
  let phone = '1' + (new Random()).string(10, '0123456789');
  let password = '123456';

  let result = await registerWithPhone(phone, password);

  let userDoc = await User.findOne({ phone: phone });
  expect(userDoc).toBeTruthy();
  expect(result.uid).toMatch(userDoc.id);
  expect(result.phone).toMatch(userDoc.phone);
});
